package com.accesshollywood.xmas2011.core;

import java.util.Random;

import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Vec2;

public class GroundShape extends PolygonShape {
	public float launchHeight = 0;
	
	public GroundShape(float W, float H, float launchHeight, int count){
		this.launchHeight = launchHeight;
		Random R = new Random();
		float step = W / (float)count;
		Vec2[] vertices = new Vec2[count+2];
		
		vertices[0] = new Vec2( 0*step, launchHeight);
		vertices[1] = new Vec2( 1*step, launchHeight);
		vertices[2] = new Vec2( 2*step, launchHeight + launchHeight/4.0f);
		vertices[6] = new Vec2( 6*step, -H + (R.nextFloat() * H/2.0f));
		
		float deltaY = (vertices[2].y-vertices[6].y) / 4.0f;
		
		vertices[3] = new Vec2( 3*step, 1 * deltaY + vertices[2].y);
		vertices[4] = new Vec2( 4*step, 2 * deltaY + vertices[2].y);
		vertices[5] = new Vec2( 5*step, 3 * deltaY + vertices[2].y);

		vertices[count] = new Vec2(vertices[count-1].x, vertices[count-1].y-4);
		vertices[count+1] = new Vec2(vertices[0].x, vertices[0].y-4);
		
		for(int i = 0; i < count; i++){
			System.out.println(i + "   " + vertices[i].toString());
		}
		
		this.set(vertices, vertices.length);// .setAsBox(48/DPI, 65/DPI);
	}
}
